//
//  Notification.swift
//  RNAsmanMaster
//
//  Created by 李旭峰 on 10/16/19.
//  Copyright © 2019 Facebook. All rights reserved.
//

import Foundation

protocol NotificationSettable {
    associatedtype defaultKeys: RawRepresentable
}
extension NotificationSettable  where defaultKeys.RawValue == String {
    static func addObserver(observer:Any, sel:Selector,forKey key:defaultKeys, object: Any?){
        NotificationCenter.default.addObserver(observer, selector: sel, name: NSNotification.Name(rawValue: key.rawValue), object: object)
    }
    static func removeObserver(observer:Any,forKey key:defaultKeys, object:Any?){
        NotificationCenter.default.removeObserver(observer, name: NSNotification.Name(rawValue: key.rawValue), object: object)
    }
    static func post(forKey key:defaultKeys,object:Any? = nil,userInfo:[AnyHashable:Any]? = nil){
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: key.rawValue), object: object, userInfo: userInfo)
    }
}
